package cn.car91.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;
import cn.car91.R;

public class PageControlView extends LinearLayout {
    private Context context;

    public PageControlView(Context context) {
        super(context);
        this.context = context;
    }

    public void bindViewFlipper(ViewFlipper viewFlipper) {
        screenChange(viewFlipper.getDisplayedChild(), viewFlipper.getChildCount());
    }

    public PageControlView(Context context, AttributeSet attr) {
        super(context, attr);
        this.context = context;
    }

    public void screenChange(int currentTab, int totalTab) {
        this.removeAllViews();
        for (int i = 0; i < totalTab; i++) {
            ImageView iv = new ImageView(context);
            LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            lp.setMargins(28, 0, 28, 0);
            iv.setLayoutParams(lp);
            if (i == currentTab) {
                iv.setImageResource(R.drawable.page_indicator_focused);
            } else {
                iv.setImageResource(R.drawable.page_indicator);
            }
            this.addView(iv);
        }
    }
}
